package com.whiteseason.whitebot.plugin;

import net.lz1998.cq.event.message.CQGroupMessageEvent;
import net.lz1998.cq.event.message.CQPrivateMessageEvent;
import net.lz1998.cq.robot.CQPlugin;
import net.lz1998.cq.robot.CoolQ;
import net.lz1998.cq.utils.CQCode;
import org.springframework.stereotype.Component;

@Component
public class FilterPlugin extends CQPlugin {
    @Override
    public int onPrivateMessage(CoolQ cq, CQPrivateMessageEvent event) {
        String msg = event.getMessage();
        StringBuilder handlemsg = new StringBuilder(msg);
        if(msg.startsWith("!") || msg.startsWith("！")){
          handlemsg.deleteCharAt(0);
          event.setMessage(CQCode.unescape(handlemsg.toString()));
          return MESSAGE_IGNORE;
        }
        return MESSAGE_BLOCK;
    }

    @Override
    public int onGroupMessage(CoolQ cq, CQGroupMessageEvent event) {
        String msg = event.getMessage();
        StringBuilder handlemsg = new StringBuilder(msg);
        if(msg.startsWith("!") || msg.startsWith("！")){
            handlemsg.deleteCharAt(0);
            event.setMessage(CQCode.unescape(handlemsg.toString()));
            return MESSAGE_IGNORE;
        }
        return MESSAGE_BLOCK;
    }
}
